package priv.zxj.social_information.sys.service.impl;

import com.google.code.kaptcha.Producer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import priv.zxj.social_information.sys.service.SysCaptchaService;
import priv.zxj.social_information.utils.RedisUtils;

import java.awt.image.BufferedImage;

/**
 * @author ZhangXinYu
 * @date 2022/10/18
 */
@Service("SysCaptchaService")
public class SysCaptchaServiceImpl implements SysCaptchaService {

    @Autowired
    private Producer producer;

    @Autowired
    private RedisUtils redisUtils;


    @Override
    public BufferedImage getCaptcha() {
        //生成文字验证码
        String code = producer.createText();
        //5分钟后过期
        redisUtils.set("code",code,180);

        return producer.createImage(code);
    }
}
